<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page language="java" import="com.moto.enums.UserStatus"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>摩旅圈App后台管理</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/style.default.css"
	type="text/css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/prettify/prettify.css"
	type="text/css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/prettify/prettify.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/custom.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.dataTables.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-migrate-1.1.1.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.flot.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.flot.resize.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.cookie.js"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/excanvas.min.js"></script><![endif]-->
</head>

<body>

	<div class="mainwrapper">

		<!-- START OF LEFT PANEL -->
		<div class="leftpanel">

			<div class="logopanel">
				<h1>
					<a href="${pageContext.request.contextPath}/index.jsp">摩旅圈 <span>v1.0</span></a>
				</h1>
			</div>
			<!--logopanel-->

			<div class="leftmenu">
				<ul class="nav nav-tabs nav-stacked">
					<li class="nav-header">主功能</li>
					<li class="dropdown"><a
						href="${pageContext.request.contextPath}/index.jsp"><span
							class="icon-pencil"></span> 发帖</a>
						<ul>
							<li><a
								href="${pageContext.request.contextPath}/post_find.jsp">发现贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/post_picture.jsp">图文贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/post_team.jsp">组队贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/post_trade.jsp">交易贴</a></li>
						</ul></li>
					<li class="dropdown"><a
						href="${pageContext.request.contextPath}/post_elite.jsp"><span
							class=" icon-edit"></span> 帖子管理</a>
						<ul>
							<li><a
								href="${pageContext.request.contextPath}/posts/getAllPostsDiscover">发现贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/posts/getPostsPic">图文贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/posts/getPostsFriend">组队贴</a></li>
							<li><a
								href="${pageContext.request.contextPath}/posts/getPostsTrade">交易贴</a></li>
						</ul></li>
					<li class="dropdown"><a
						href="${pageContext.request.contextPath}/media.jsp"><span
							class="icon-picture"></span> App图片</a>
						<ul>
							<li><a href="${pageContext.request.contextPath}/welcome.jsp">欢迎页配置</a></li>
							<li><a
								href="${pageContext.request.contextPath}/start_pic.jsp">首页轮播图</a></li>
						</ul></li>
					<li><a href="${pageContext.request.contextPath}/user/userList"><span
							class="iconsweets-male"></span> 用户管理</a></li>

				</ul>
			</div>
			<!--leftmenu-->

		</div>
		<!--mainleft-->
		<!-- END OF LEFT PANEL -->

		<!-- START OF RIGHT PANEL -->
		<div class="rightpanel">
			<div class="headerpanel">
				<a href="" class="showmenu"></a>

				<div class="headerright">
					<div class="dropdown userinfo">
						<a class="dropdown-toggle" data-toggle="dropdown" data-target="#"
							href="/page.jsp">Hi, ${sessionScope.username}&nbsp;! <b class="caret"></b></a>
						<ul class="dropdown-menu">
							<%-- <li><a href="${pageContext.request.contextPath}/index.jsp"><span
									class="icon-edit"></span> 修改密码</a></li> 
							<li class="divider"></li>--%>
							<li><a href="${pageContext.request.contextPath}/login.jsp"><span
									class="icon-off"></span> 退出</a></li>
						</ul>
					</div>
					<!--dropdown-->

				</div>
				<!--headerright-->

			</div>
			<!--headerpanel-->
			<div class="breadcrumbwidget">
				<!-- <ul class="skins">
					<li><a href="default" class="skin-color default"></a></li>
					<li><a href="orange" class="skin-color orange"></a></li>
					<li><a href="dark" class="skin-color dark"></a></li>
					<li>&nbsp;</li>
					<li class="fixed"><a href="" class="skin-layout fixed"></a></li>
					<li class="wide"><a href="" class="skin-layout wide"></a></li>
				</ul> -->
				<!--skins-->
				<ul class="breadcrumb">
					<li><a href="${pageContext.request.contextPath}/index.jsp">Home</a>
						<span class="divider">/</span></li>
					<li class="active">发现贴管理</li>
				</ul>
			</div>
			<!--breadcrumbwidget-->

			<div class="maincontent">
				<div class="contentinner">

					<div class="widgetcontent">

						<table class="table table-bordered" id="dyntable">
							<thead>
								<tr>
									<th>帖子主题</th>
									<th class="center">帖子状态</th>
									<th class="center">帖子精华</th>
									<th class="center">帖子修改</th>
									<th class="center">帖子删除</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${discoverPosts}" var="item"
									varStatus="status">
									<tr>
										<td><a
											href="${pageContext.request.contextPath}/post_find_edit.jsp?id=${item.postsId}"><strong>${item.postsSubject}</strong></a></td>
										<c:choose>
											<c:when test="${item.postsIsElite eq '0'}">
												<td class="center">精华贴</td>
												<td class="center">
													<button type="reset" class="btn btn-success"
														onclick="lock(this);" value="${item.postsId}">
														<span id="lock" class="icon-star"></span>&nbsp;去精
													</button>
												</td>
											</c:when>
											<c:otherwise>
												<td class="center">正常贴</td>
												<td class="center">
													<button type="reset" class="btn" onclick="lock(this);"
														value="${item.postsId}">
														<span id="lock" class="icon-star-empty"></span>&nbsp;加精
													</button>
												</td>
											</c:otherwise>
										</c:choose>
										<td class="center"><a
											href="${pageContext.request.contextPath}/post_find_edit.jsp?id=${item.postsId}"
											class="btn btn-info"><span class="icon-edit"></span>&nbsp;修改</a></td>
										<td class="center">
											<button type="reset" class="btn btn-danger"
												onclick="deletePost(this);" value="${item.postsId}">
												<span id="lock" class="icon-trash"></span>&nbsp;删除
											</button>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
		<script>
			var jq = jQuery.noConflict();
			var apiUrl = "${pageContext.request.contextPath}";
			function lock(obj) {
				var postsId = jq(obj).val();
				var lock_class = jq(obj).children("#lock").attr("class");
				if (lock_class.indexOf("empty") != -1) {
					jq
							.ajax({
								url : apiUrl + "/posts/addDigest",
								type : 'GET',
								data : {
									'postsId' : postsId,
								},
								dataType : 'json',
								success : function(result) {

									if (result = true) {
										jq(obj).removeClass("btn");
										jq(obj).addClass("btn btn-success");
										jq(obj).html("");
										jq(obj)
												.append(
														"<span id='lock' class='icon-star'></span>&nbsp;去精");
										jq(obj).parent('td').prev().html("精华帖");
									} else {

									}
								},
								error : function() {
									alert("错误！");

								}
							})
				} else {
					jq
							.ajax({
								url : apiUrl + "/posts/deleteDigest",
								type : 'GET',
								data : {
									'postsId' : postsId,
								},
								dataType : 'json',
								success : function(result) {
									if (result = true) {
										jq(obj).removeClass("btn btn-success");
										jq(obj).addClass("btn");
										jq(obj).html("");
										jq(obj)
												.append(
														"<span id='lock' class='icon-star-empty'></span>&nbsp;加精");
										jq(obj).parent('td').prev().html("正常贴");
									} else {

									}
								},
								error : function() {
									alert("错误！");
								}
							})
				}
			}
			function deletePost(obj) {
				var postsId = jq(obj).val();
				var sure = confirm('确定删除吗？', function() {
				}, null);
				if (sure) {
					jq.ajax({
						url : apiUrl + "/posts/delete",
						type : 'GET',
						data : {
							'postsId' : postsId,
						},
						dataType : 'json',
						success : function(result) {

							if (result = true) {
								location.href = apiUrl
										+ "/posts/getAllPostsDiscover";
							} else {

							}
						},
						error : function() {
							alert("错误！");

						}
					})
				}
			}
		</script>
</body>
</html>
